home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Cream of the Crop 25
/
Cream of the Crop 25.iso
/
faq
/
wdj0597.zip
/
SDKANN.ZIP
/
SOURCE.ZIP
/
ANNCONV.C
< prev
next >
Wrap
C/C++ Source or Header
|
1997-01-09
|
4KB
|
171 lines
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifndef TRUE
# define TRUE 1
#endif
#ifndef FALSE
# define FALSE 0
#endif
char *Value(char*In)
{
while(*In && *In != ' ' && *In != '\t')
++In;
while(*In && (*In == ' ' || *In == '\t'))
++In;
return In;
}
void OutputString(FILE* Out, char *Line)
{
while(*Line)
{
if(*Line == '\"')
fprintf(Out, "\\042");
else if(*Line == '\\')
fprintf(Out, "\\\\");
else
fprintf(Out, "%c", *Line);
++Line;
}
}
void OutputLine(FILE* Out, char *Line)
{
while(*Line)
{
if(*Line == '\"')
fprintf(Out, "\\042");
else if(*Line == '\\')
fprintf(Out, "\\\\");
else
fprintf(Out, "%c", *Line);
++Line;
}
}
int GetLine(FILE* In, char*Out)
{
if(!fgets(Out, 127, In))
return FALSE;
else
{
int Len = strlen(Out);
if(Len > 0)
Out[Len-1] = '\0';
return Len;
}
}
void DoAnnotation(FILE* In, FILE* Out, char* Line, int Num)
{
int NewLine;
char Type[128];
char Topic[128];
char Keyword[128];
char *Number = strchr(Line, '#');
GetLine(In, Type);
GetLine(In, Topic);
GetLine(In, Keyword);
if(!strcmpi(Value(Type), "Win3.1"))
strcpy(Type, "win31wh.hlp");
else if(!strcmpi(Value(Type), "Win16"))
strcpy(Type, "win31wh.hlp");
else if(!strncmp(Value(Type), "MFC", 3))
strcpy(Type, "mfc30.hlp");
else if(!strcmpi(Value(Type), "Win32"))
strcpy(Type, "win32.hlp");
else
printf("Bad type? : '%s'\n", Value(Type));
fprintf(Out, "%d\tRCDATA\nbegin\n", Num);
fprintf(Out, "\t\"%s\\0\"\n", Type);
fprintf(Out, "\t\"%s\t%s\\0\"\n", Number, Value(Topic));
fprintf(Out, "\t\"");
OutputString(Out, Value(Keyword));
fprintf(Out, "\\0\"\n");
fprintf(Out, "\t\"%s\\0\"\n", Value(Topic));
fprintf(Out, "\n");
fprintf(Out, "\"%s\"\n", Line);
NewLine = FALSE;
while(GetLine(In, Line))
{
int Len = strlen(Line);
if(!strncmp(Line, "--------", 8))
break;
if(Len == 0)
{
if(!NewLine)
fprintf(Out, "\"\\r\\n\"\n");
fprintf(Out, "\"\\r\\n\"\n");
NewLine = TRUE;
}
else if(Len > 0)
{
if(Line[0] == ' ' || Line[0] == '\t')
if(!NewLine)
{
NewLine = TRUE;
fprintf(Out, "\"\\r\\n\"\n");
}
if(Line[Len-1] == '^' || Line[0] == ' ' || Line[0] == '\t')
{
if(Line[Len-1] == '^')
Line[Len-1] = '\0';
fprintf(Out, "\"");
OutputLine(Out, Line);
fprintf(Out, "\\r\\n\"\n", Line);
NewLine = TRUE;
}
else
{
fprintf(Out, "\"");
OutputLine(Out, Line);
fprintf(Out, " \"\n");
NewLine = FALSE;
}
}
}
fprintf(Out, "\"\\0\\0\\0\\0\"\nend\n\n");
}
void Process(FILE *In, FILE *Out)
{
static char Line[1024];
int Num = 0;
while(GetLine(In, Line))
{
if(!strncmp(Line, "WDJ SDK Annotation #", 20)
|| !strncmp(Line, "WDJ MFC Annotation #", 20))
{
DoAnnotation(In, Out, Line, ++Num);
}
else if(!strncmp(Line, "WDJ ", 4))
printf("Bad line? : %s\n", Line);
}
printf( "Processed %d annotations\n", Num);
}
void main()
{
FILE *Fin = fopen("..\\sdkann.txt", "r");
FILE *Fout = fopen("annotate.rc", "w");
if(!Fin)
{
printf("Could not open '..\\sdkann.txt' for input\n");
exit(EXIT_FAILURE);
}
if(!Fout)
{
printf("Could not open 'annotate.rc' for output\n");
exit(EXIT_FAILURE);
}
Process(Fin, Fout);
}